package org.opentcs.kernel.extensions;

import lombok.Getter;
import org.opentcs.util.fsy.JsonBinder;

@Getter
public class WebResult {
  private final String msg;
  private final Integer errorCode;
  private final Object data;

  public WebResult(String msg, int errorCode, Object data) {
    this.msg = msg;
    this.errorCode = errorCode;
    this.data = data;
  }


  public static String success(Object data) {
    JsonBinder jsonBinder = new JsonBinder();
    return jsonBinder.toJson(new WebResult("success", 0, data));
  }

  public static String error(String msg) {
    JsonBinder jsonBinder = new JsonBinder();
    return jsonBinder.toJson(new WebResult(msg, 1, null));
  }

}
